home *** CD-ROM | disk | FTP | other *** search
/ Symantec Visual Cafe for Java 2.5 / symantec-visual-cafe-2.5-database-dev-edition.iso / Visual Cafe Pro v1.0 / TUTORIAL.BIN / ProjBinder.class (.txt) < prev    next >
Encoding:
Java Class File  |  1997-01-30  |  14.0 KB  |  549 lines

  1. package symantec.itools.db.pro;
  2.  
  3. import java.io.IOException;
  4. import java.io.InputStream;
  5. import java.io.StringBufferInputStream;
  6. import java.util.Vector;
  7. import symjava.lang.Bignum;
  8. import symjava.sql.Date;
  9. import symjava.sql.SQLException;
  10. import symjava.sql.Time;
  11. import symjava.sql.Timestamp;
  12.  
  13. public class ProjBinder {
  14.    Vector _links;
  15.    int _id;
  16.    RelationView _rv;
  17.    boolean _inSetDataNotify;
  18.    boolean _enabled;
  19.    boolean _columnIsWriteable;
  20.    public static final int DEFAULTSCALE = 0;
  21.    public static final int SETBLANKTODEFAULT = 0;
  22.    public static final int SETBLANKTONULL = 1;
  23.    public static final int SETBLANKTOEMPTY = 2;
  24.  
  25.    ProjBinder(int colID, RelationView rv, boolean enabled) {
  26.       this._id = colID;
  27.       this._rv = rv;
  28.       this._links = new Vector();
  29.       this._inSetDataNotify = false;
  30.       this._enabled = enabled;
  31.       this._columnIsWriteable = true;
  32.  
  33.       try {
  34.          RelationViewMetaData md = rv.getMetaData();
  35.          int type = md.getColumnType(colID);
  36.          if (type == -1 || type == -2 || type == -3 || type == -4 || type == 1111) {
  37.             this._columnIsWriteable = false;
  38.          }
  39.  
  40.       } catch (SQLException var6) {
  41.          this._columnIsWriteable = false;
  42.       }
  43.    }
  44.  
  45.    void addLink(ProjLink link) {
  46.       if (!this._links.contains(link)) {
  47.          this._links.addElement(link);
  48.       }
  49.  
  50.    }
  51.  
  52.    boolean bindsExist() {
  53.       return this._links.size() > 0;
  54.    }
  55.  
  56.    void removeLink(Object link) {
  57.       this._links.removeElement(link);
  58.    }
  59.  
  60.    void removeAllLinks() {
  61.       this._links.removeAllElements();
  62.    }
  63.  
  64.    void notifyDataChange() {
  65.       if (this._enabled && !this._inSetDataNotify) {
  66.          for(int i = 0; i < this._links.size(); ++i) {
  67.             ProjLink link = (ProjLink)this._links.elementAt(i);
  68.             link.notifyDataChange(this);
  69.          }
  70.       }
  71.  
  72.    }
  73.  
  74.    boolean notifySetData() throws SQLException {
  75.       boolean setDataResult = true;
  76.       if (this._enabled) {
  77.          this._inSetDataNotify = true;
  78.  
  79.          for(int i = 0; i < this._links.size(); ++i) {
  80.             ProjLink link = (ProjLink)this._links.elementAt(i);
  81.             if (!link.notifySetData(this)) {
  82.                setDataResult = false;
  83.                break;
  84.             }
  85.          }
  86.  
  87.          this._inSetDataNotify = false;
  88.       }
  89.  
  90.       return setDataResult;
  91.    }
  92.  
  93.    void enable(boolean enable) {
  94.       this._enabled = enable;
  95.    }
  96.  
  97.    public boolean isWritable() throws SQLException {
  98.       return this._rv.isCurrentRecordWritable() && this._columnIsWriteable;
  99.    }
  100.  
  101.    public boolean isReadable() throws SQLException {
  102.       return this._rv.isCurrentRecordReadable();
  103.    }
  104.  
  105.    public String getColumnName() throws SQLException {
  106.       RelationViewMetaData md = this._rv.getMetaData();
  107.       return md.getColumnName(this._id);
  108.    }
  109.  
  110.    public RelationView getRelationView() throws SQLException {
  111.       return this._rv;
  112.    }
  113.  
  114.    public boolean isNull() throws SQLException {
  115.       return this._rv.isNull(this._id);
  116.    }
  117.  
  118.    public String getString() throws SQLException {
  119.       return this._rv.getString(this._id);
  120.    }
  121.  
  122.    public boolean getBoolean() throws SQLException {
  123.       return this._rv.getBoolean(this._id);
  124.    }
  125.  
  126.    public byte getByte() throws SQLException {
  127.       return this._rv.getByte(this._id);
  128.    }
  129.  
  130.    public short getShort() throws SQLException {
  131.       return this._rv.getShort(this._id);
  132.    }
  133.  
  134.    public int getInt() throws SQLException {
  135.       return this._rv.getInt(this._id);
  136.    }
  137.  
  138.    public long getLong() throws SQLException {
  139.       return this._rv.getLong(this._id);
  140.    }
  141.  
  142.    public float getFloat() throws SQLException {
  143.       return this._rv.getFloat(this._id);
  144.    }
  145.  
  146.    public double getDouble() throws SQLException {
  147.       return this._rv.getDouble(this._id);
  148.    }
  149.  
  150.    public Bignum getBignum(int scale) throws SQLException {
  151.       return this._rv.getBignum(this._id, scale);
  152.    }
  153.  
  154.    public byte[] getBytes() throws SQLException {
  155.       return this._rv.getBytes(this._id);
  156.    }
  157.  
  158.    public Date getDate() throws SQLException {
  159.       return this._rv.getDate(this._id);
  160.    }
  161.  
  162.    public Time getTime() throws SQLException {
  163.       return this._rv.getTime(this._id);
  164.    }
  165.  
  166.    public Timestamp getTimestamp() throws SQLException {
  167.       return this._rv.getTimestamp(this._id);
  168.    }
  169.  
  170.    public InputStream getAsciiStream() throws SQLException {
  171.       return this._rv.getAsciiStream(this._id);
  172.    }
  173.  
  174.    public InputStream getUnicodeStream() throws SQLException {
  175.       return this._rv.getUnicodeStream(this._id);
  176.    }
  177.  
  178.    public InputStream getBinaryStream() throws SQLException {
  179.       return this._rv.getBinaryStream(this._id);
  180.    }
  181.  
  182.    public String getStringValue(int scale) throws SQLException, IOException {
  183.       RelationViewMetaData md = this._rv.getMetaData();
  184.       int columnType = md.getColumnType(this._id);
  185.       return this.getStringValue(columnType, scale, false);
  186.    }
  187.  
  188.    public String getStringValue(int scale, boolean processBinaryData) throws SQLException, IOException {
  189.       RelationViewMetaData md = this._rv.getMetaData();
  190.       int columnType = md.getColumnType(this._id);
  191.       return this.getStringValue(columnType, scale, processBinaryData);
  192.    }
  193.  
  194.    public String getStringValue() throws SQLException, IOException {
  195.       RelationViewMetaData md = this._rv.getMetaData();
  196.       int columnType = md.getColumnType(this._id);
  197.       return this.getStringValue(columnType, 0, false);
  198.    }
  199.  
  200.    public String getStringValue(boolean processBinaryData) throws SQLException, IOException {
  201.       RelationViewMetaData md = this._rv.getMetaData();
  202.       int columnType = md.getColumnType(this._id);
  203.       return this.getStringValue(columnType, 0, processBinaryData);
  204.    }
  205.  
  206.    public String getStringValue(String columnTypeName, int scale) throws SQLException, IOException {
  207.       int columnType = RelationView.sqlTypeConvert(columnTypeName);
  208.       return this.getStringValue(columnType, scale, false);
  209.    }
  210.  
  211.    public String getStringValue(String columnTypeName, int scale, boolean processBinaryData) throws SQLException, IOException {
  212.       int columnType = RelationView.sqlTypeConvert(columnTypeName);
  213.       return this.getStringValue(columnType, scale, processBinaryData);
  214.    }
  215.  
  216.    public String getStringValue(int columnType, int scale) throws SQLException, IOException {
  217.       return this.getStringValue(columnType, scale, false);
  218.    }
  219.  
  220.    public String getStringValue(int columnType, int scale, boolean processBinaryData) throws SQLException, IOException {
  221.       int length = scale;
  222.       if (scale == 0) {
  223.          RelationViewMetaData md = this._rv.getMetaData();
  224.          scale = md.getScale(this._id);
  225.          length = md.getColumnDisplaySize(this._id);
  226.       }
  227.  
  228.       String value = "";
  229.       if (!this.isNull()) {
  230.          switch (columnType) {
  231.             case -7:
  232.                value = String.valueOf(this.getBoolean());
  233.                break;
  234.             case -6:
  235.                value = String.valueOf(this.getByte());
  236.                break;
  237.             case -5:
  238.                value = String.valueOf(this.getLong());
  239.                break;
  240.             case -4:
  241.                if (processBinaryData) {
  242.                   InputStream lvbIs = this.getBinaryStream();
  243.                   value = RelationView.binaryStreamtoString(lvbIs, length);
  244.                } else {
  245.                   value = "<Binary Data>";
  246.                }
  247.                break;
  248.             case -3:
  249.                if (processBinaryData) {
  250.                   byte[] vbinb = new byte[length];
  251.                   vbinb = this.getBytes();
  252.                   value = RelationView.binaryArraytoString(vbinb);
  253.                } else {
  254.                   value = "<Binary Data>";
  255.                }
  256.                break;
  257.             case -2:
  258.                if (processBinaryData) {
  259.                   byte[] binb = new byte[length];
  260.                   binb = this.getBytes();
  261.                   value = RelationView.binaryArraytoString(binb);
  262.                } else {
  263.                   value = "<Binary Data>";
  264.                }
  265.                break;
  266.             case -1:
  267.                InputStream lvcIs = this.getAsciiStream();
  268.                value = RelationView.asciiStreamtoString(lvcIs);
  269.                break;
  270.             case 0:
  271.                value = "";
  272.                break;
  273.             case 1:
  274.                value = this.getString();
  275.                break;
  276.             case 2:
  277.                Bignum n = this.getBignum(scale);
  278.                if (n != null) {
  279.                   value = String.valueOf(n);
  280.                }
  281.                break;
  282.             case 3:
  283.                Bignum d = this.getBignum(scale);
  284.                if (d != null) {
  285.                   value = String.valueOf(d);
  286.                }
  287.                break;
  288.             case 4:
  289.                value = String.valueOf(this.getInt());
  290.                break;
  291.             case 5:
  292.                value = String.valueOf(this.getShort());
  293.                break;
  294.             case 6:
  295.                value = this.getString();
  296.                break;
  297.             case 7:
  298.                value = this.getString();
  299.                break;
  300.             case 8:
  301.                value = this.getString();
  302.                break;
  303.             case 12:
  304.                value = this.getString();
  305.                break;
  306.             case 91:
  307.                Date dt = this.getDate();
  308.                if (dt != null) {
  309.                   value = dt.toString();
  310.                }
  311.                break;
  312.             case 92:
  313.                Time tm = this.getTime();
  314.                if (tm != null) {
  315.                   value = tm.toString();
  316.                }
  317.                break;
  318.             case 93:
  319.                Timestamp ts = this.getTimestamp();
  320.                if (ts != null) {
  321.                   value = ts.toString();
  322.                }
  323.                break;
  324.             case 1111:
  325.                if (processBinaryData) {
  326.                   InputStream uniIs = this.getUnicodeStream();
  327.                   value = RelationView.binaryStreamtoString(uniIs, length);
  328.                } else {
  329.                   value = "<Other Data Type>";
  330.                }
  331.                break;
  332.             default:
  333.                value = this.getString();
  334.          }
  335.       }
  336.  
  337.       return value;
  338.    }
  339.  
  340.    public void setNull(int sqlType) throws SQLException {
  341.       this._rv.setNull(this._id, sqlType);
  342.    }
  343.  
  344.    public void setBoolean(boolean x) throws SQLException {
  345.       this._rv.setBoolean(this._id, x);
  346.    }
  347.  
  348.    public void setByte(byte x) throws SQLException {
  349.       this._rv.setByte(this._id, x);
  350.    }
  351.  
  352.    public void setShort(short x) throws SQLException {
  353.       this._rv.setShort(this._id, x);
  354.    }
  355.  
  356.    public void setInt(int x) throws SQLException {
  357.       this._rv.setInt(this._id, x);
  358.    }
  359.  
  360.    public void setLong(long x) throws SQLException {
  361.       this._rv.setLong(this._id, x);
  362.    }
  363.  
  364.    public void setFloat(float x) throws SQLException {
  365.       this._rv.setFloat(this._id, x);
  366.    }
  367.  
  368.    public void setDouble(double x) throws SQLException {
  369.       this._rv.setDouble(this._id, x);
  370.    }
  371.  
  372.    public void setBignum(Bignum x) throws SQLException {
  373.       this._rv.setBignum(this._id, x);
  374.    }
  375.  
  376.    public void setString(String x) throws SQLException {
  377.       this._rv.setString(this._id, x);
  378.    }
  379.  
  380.    public void setBytes(byte[] x) throws SQLException {
  381.       this._rv.setBytes(this._id, x);
  382.    }
  383.  
  384.    public void setDate(Date x) throws SQLException {
  385.       this._rv.setDate(this._id, x);
  386.    }
  387.  
  388.    public void setTime(Time x) throws SQLException {
  389.       this._rv.setTime(this._id, x);
  390.    }
  391.  
  392.    public void setTimestamp(Timestamp x) throws SQLException {
  393.       this._rv.setTimestamp(this._id, x);
  394.    }
  395.  
  396.    public void setAsciiStream(InputStream x, int length) throws SQLException {
  397.       this._rv.setAsciiStream(this._id, x, length);
  398.    }
  399.  
  400.    public void setUnicodeStream(InputStream x, int length) throws SQLException {
  401.       this._rv.setUnicodeStream(this._id, x, length);
  402.    }
  403.  
  404.    public void setBinaryStream(InputStream x, int length) throws SQLException {
  405.       this._rv.setBinaryStream(this._id, x, length);
  406.    }
  407.  
  408.    public void setValueFromString(String data, int scale, int treatBlankAsNull) throws SQLException, IOException {
  409.       RelationViewMetaData md = this._rv.getMetaData();
  410.       int columnType = md.getColumnType(this._id);
  411.       this.setValueFromString(data, columnType, scale, treatBlankAsNull);
  412.    }
  413.  
  414.    public void setValueFromString(String data) throws SQLException, IOException {
  415.       RelationViewMetaData md = this._rv.getMetaData();
  416.       int columnType = md.getColumnType(this._id);
  417.       this.setValueFromString(data, columnType, 0, 0);
  418.    }
  419.  
  420.    public void setValueFromString(String data, int treatBlankAsNull) throws SQLException, IOException {
  421.       RelationViewMetaData md = this._rv.getMetaData();
  422.       int columnType = md.getColumnType(this._id);
  423.       this.setValueFromString(data, columnType, 0, treatBlankAsNull);
  424.    }
  425.  
  426.    public void setValueFromString(String data, String columnTypeName, int scale) throws SQLException, IOException {
  427.       int columnType = RelationView.sqlTypeConvert(columnTypeName);
  428.       this.setValueFromString(data, columnType, scale, 0);
  429.    }
  430.  
  431.    public void setValueFromString(String data, String columnTypeName, int scale, int treatBlankAsNull) throws SQLException, IOException {
  432.       int columnType = RelationView.sqlTypeConvert(columnTypeName);
  433.       this.setValueFromString(data, columnType, scale, treatBlankAsNull);
  434.    }
  435.  
  436.    public void setValueFromString(String data, int columnType, int scale, int treatBlankAsNull) throws SQLException, IOException {
  437.       if (data == null || data.compareTo("") == 0) {
  438.          data = RelationView.processEmptyStringData(data, this._rv, this._id, columnType, treatBlankAsNull);
  439.          if (data == null) {
  440.             this.setNull(columnType);
  441.             return;
  442.          }
  443.       }
  444.  
  445.       switch (columnType) {
  446.          case -7:
  447.             boolean b = new Boolean(data);
  448.             this.setBoolean(b);
  449.             return;
  450.          case -6:
  451.             byte ti = (byte)Integer.valueOf(data);
  452.             this.setByte(ti);
  453.             return;
  454.          case -5:
  455.             long l = Long.valueOf(data);
  456.             this.setFloat((float)l);
  457.             return;
  458.          case -4:
  459.             int lvblen = data.length();
  460.             StringBufferInputStream lvbbsstm = new StringBufferInputStream(data);
  461.             this.setBinaryStream(lvbbsstm, lvblen);
  462.             return;
  463.          case -3:
  464.             byte[] vbarray = new byte[data.length()];
  465.             data.getBytes(0, data.length(), vbarray, 0);
  466.             this.setBytes(vbarray);
  467.             return;
  468.          case -2:
  469.             byte[] barray = new byte[data.length()];
  470.             data.getBytes(0, data.length(), barray, 0);
  471.             this.setBytes(barray);
  472.             return;
  473.          case -1:
  474.             int lvclen = data.length();
  475.             StringBufferInputStream lvcbsstm = new StringBufferInputStream(data);
  476.             this.setAsciiStream(lvcbsstm, lvclen);
  477.             return;
  478.          case 0:
  479.             this.setNull(columnType);
  480.             return;
  481.          case 1:
  482.             this.setString(data);
  483.             return;
  484.          case 2:
  485.             if (scale == 0) {
  486.                Bignum n = new Bignum(data);
  487.                this.setBignum(n);
  488.                return;
  489.             }
  490.  
  491.             Bignum n = new Bignum(data, scale);
  492.             this.setBignum(n);
  493.             return;
  494.          case 3:
  495.             if (scale == 0) {
  496.                Bignum dec = new Bignum(data);
  497.                this.setBignum(dec);
  498.                return;
  499.             }
  500.  
  501.             Bignum dec = new Bignum(data, scale);
  502.             this.setBignum(dec);
  503.             return;
  504.          case 4:
  505.             int i = Integer.valueOf(data);
  506.             this.setInt(i);
  507.             return;
  508.          case 5:
  509.             short si = (short)Integer.valueOf(data);
  510.             this.setShort(si);
  511.             return;
  512.          case 6:
  513.             this.setString(data);
  514.             return;
  515.          case 7:
  516.             this.setString(data);
  517.             return;
  518.          case 8:
  519.             this.setString(data);
  520.             return;
  521.          case 12:
  522.             this.setString(data);
  523.             return;
  524.          case 91:
  525.             Date dt = null;
  526.             dt = Date.valueOf(data);
  527.             this.setDate(dt);
  528.             return;
  529.          case 92:
  530.             Time t = null;
  531.             t = Time.valueOf(data);
  532.             this.setTime(t);
  533.             return;
  534.          case 93:
  535.             Timestamp ts = null;
  536.             ts = Timestamp.valueOf(data);
  537.             this.setTimestamp(ts);
  538.             return;
  539.          case 1111:
  540.             int unilen = data.length();
  541.             StringBufferInputStream unibsstm = new StringBufferInputStream(data);
  542.             this.setBinaryStream(unibsstm, unilen);
  543.             return;
  544.          default:
  545.             this.setString(data);
  546.       }
  547.    }
  548. }
  549.